﻿using System;
using System.Net;
using System.Text.RegularExpressions;

namespace Hacker
{
    internal class Program
    {
        /// <summary>
        /// 下载校园网所有图片
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            WebClient web = new WebClient();
            string html = web.DownloadString("http://www.lzzy.net");

            MatchCollection mc = Regex.Matches(html, @"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>");
            int i = 0;
            foreach (Match item in mc)
            {
                if (item.Success)
                {
                    i++;
                    Console.WriteLine(item.Value);
                    //获得原路径
                    string src = "http://www.lzzy.net/" + item.Groups["Src"].Value;
                    //下载到电脑上的路径
                    string target = @"C:\BBB" + "\\lzzy\\" + i + ".jpg";
                    //开始下载
                    web.DownloadFile(src, target);
                }
            }
            Console.WriteLine("下载成功！！！！");
        }
    }
}
